import json
from flask import Flask, Blueprint, Response, request
from flask_jwt_extended import  jwt_required
from app.service.portraitJyfxSffxTabService import PortraitJyfxSffxTabService
from app.common.commonMessage import CommonMassages
from app.config.db import DBUtils
from app.config.jsonEncoder import CustomJSONEncoder

app = Flask(__name__)
#创建蓝图
portrait_jyfx_sffx_tab_up = Blueprint('portrait_jyfx_sffx_tab_controller', __name__,url_prefix='/kshx')
#调用服务
portrait_jyfx_sffx_tab = PortraitJyfxSffxTabService()
#获取session
db_utils = DBUtils()
session = db_utils.get_session()


@portrait_jyfx_sffx_tab_up.route('/portrait_fxxx', methods=['GET'])
@jwt_required()
def portraitFxxx():
    # company = request.json.get("company", None)
    company = request.args.get('company')
    type = request.args.get('type')
    if company and type:
        if type == 'jyfx_gscg':
            #经营风险-公示催告
            risk_list = portrait_jyfx_sffx_tab.select_jyfx_gscg(session, company)
        elif type == 'jyfx_gqcz':
            #经营风险-股权出质
            risk_list = portrait_jyfx_sffx_tab.select_jyfx_gqcz(session, company)
        elif type == 'jyfx_dwdb':
            #经营风险-对外担保
            risk_list = portrait_jyfx_sffx_tab.select_jyfx_dwdb(session, company)
        elif type == 'jyfx_sxxx':
            #经营风险-失信信息
            risk_list = portrait_jyfx_sffx_tab.select_jyfx_sxxx(session, company)
        elif type == 'jyfx_gqzy':
            #经营风险-股权质押
            risk_list = portrait_jyfx_sffx_tab.select_jyfx_gqzy(session, company)
        elif type == 'jyfx_dcdy':
            #经营风险-动产抵押
            risk_list = portrait_jyfx_sffx_tab.select_jyfx_dcdy(session, company)
        elif type == 'jyfx_jyyc':
            #经营风险-经营异常
            risk_list = portrait_jyfx_sffx_tab.select_jyfx_jyyc(session, company)
        elif type == 'sffx_sfxz':
            #司法风险-司法协助
            risk_list = portrait_jyfx_sffx_tab.select_sffx_sfxz(session, company)
        elif type == 'sffx_ktgg':
            #司法风险-开庭公告
            risk_list = portrait_jyfx_sffx_tab.select_sffx_ktgg(session, company)
        elif type == 'sffx_qsgg':
            #司法风险-欠税公告
            risk_list = portrait_jyfx_sffx_tab.select_sffx_qsgg(session, company)
        elif type == 'sffx_flss':
            #司法风险-法律诉讼
            risk_list = portrait_jyfx_sffx_tab.select_sffx_flss(session, company)
        elif type == 'sffx_fygg':
            #司法风险-法院公告
            risk_list = portrait_jyfx_sffx_tab.select_sffx_fygg(session, company)
        elif type == 'sffx_hbcf':
            #司法风险-环保处罚
            risk_list = portrait_jyfx_sffx_tab.select_sffx_hbcf(session, company)
        elif type == 'sffx_laxx':
            #司法风险-立案信息
            risk_list = portrait_jyfx_sffx_tab.select_sffx_laxx(session, company)
        elif type == 'sffx_zbaj':
            #司法风险-终本案件
            risk_list = portrait_jyfx_sffx_tab.select_sffx_zbaj(session, company)
        elif type == 'sffx_xzcf':
            #司法风险-行政处罚
            risk_list = portrait_jyfx_sffx_tab.select_sffx_xzcf(session, company)
        elif type == 'sffx_bzxrxx':
            #司法风险-被执行人信息
            risk_list = portrait_jyfx_sffx_tab.select_sffx_bzxrxx(session, company)
        elif type == 'sffx_sdgg':
            #司法风险-送达公告
            risk_list = portrait_jyfx_sffx_tab.select_sffx_sdgg(session, company)
        elif type == 'sffx_xzxfl':
            #司法风险-限制消费令
            risk_list = portrait_jyfx_sffx_tab.select_sffx_xzxfl(session, company)
        else:
            risk_list = '错误类型'

        if risk_list is not None:
            result = {
                "code": 200,
                "data": risk_list,
                "message": CommonMassages.CCD_SELECT_SUCCESS.value
            }

        else:
            result = {
                "code": 400,
                "data": None,
                "message": CommonMassages.CCD_SELECT_FAILED.value
            }

    else:
        result = {
            "code": 400,
            "data": None,
            "message": CommonMassages.CCD_SELECT_FAILED.value
        }
    resp_data = json.dumps(result, ensure_ascii=False, cls=CustomJSONEncoder)
    return Response(resp_data)
    # return Response(json.dumps(result, ensure_ascii=False), content_type='application/json')
